package com.zhangtao.demo.controller;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public class KafkaController {
    public static void main(String[] args) throws IOException {
        URL url =new URL("https://www.jianshu.com/");
//        Proxy proxy = new Proxy(Proxy.Type.HTTP,new InetSocketAddress("118.26.147.119",80));
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setConnectTimeout(10000);
        connection.setReadTimeout(100000);
        connection.setRequestMethod("GET");
        connection.setUseCaches(true);
        connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
        connection.connect();
        System.out.println(connection.getResponseCode());
        int i = connection.getResponseCode();
        String content = "";
        if(i==HttpURLConnection.HTTP_OK){
            InputStream in = connection.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
            String line = "";
            while((line=br.readLine())!=null){
                content+=line+"\n\r\n";
            }
            System.out.println(content);
        }

    }
}
